package controller

import (
	"ce-cloud-service/internal/services/gate/hall/msg"
	"ce-cloud-service/pkg/tool"
	"ce-cloud/pkg/log"
	"errors"
	"strconv"

	//"ce-second/common/tools"
	"github.com/gin-gonic/gin"
)

// ParseSign
// @tags 测试
// @summary 解析签名
// @param sign header string true "签名"
// @success 200 {object} msg.UserLoginResponse "响应参数"
// @router /test/parseSign [get]
func ParseSign(ctx *gin.Context) {
	s := ctx.GetHeader("sign")
	data := tool.Sign{}.ParseSign(s)
	log.Infof("%+v", data)
	sendMsgToHttp(ctx, data, nil)
}

// TestPatch
// @tags 测试
// @summary 测试PATCH类型请求
// @param data body msg.TestPatchRequest true "请求参数"
// @success 200 {object} msg.TestPatchResponse "响应参数"
// @router /test [patch]
func TestPatch(ctx *gin.Context) {
	req := msg.TestPatchRequest{}
	if err := ctx.Bind(&req); err != nil {
		log.Error("TestPatch bind error:", err)
		sendMsgToHttp(ctx, nil, err)
		return
	}
	rsp := msg.TestPatchResponse{
		ParamArrayFloat: req.ParamArrayFloat,
		ParamInt:        req.ParamInt,
		ParamString:     req.ParamString,
	}
	sendMsgToHttp(ctx, rsp, nil)
	return
}

// TestGet
// @tags 测试
// @summary 测试GET类型请求
// @param param_integer query integer true "第一个整型参数"
// @param param_string query string true "第二个字符串类型的参数"
// @success 200 {object} msg.TestGetResponse "响应参数"
// @router /test [get]
func TestGet(ctx *gin.Context) {
	param1 := ctx.Query("param_integer")
	param2 := ctx.Query("param_string")
	intParam, err := strconv.Atoi(param1)
	if err != nil {
		err = errors.New("param_integer 不是整型数据")
		sendMsgToHttp(ctx, nil, err)
		return
	}
	rsp := msg.TestGetResponse{
		ParamInteger: intParam,
		ParamString:  param2,
	}
	sendMsgToHttp(ctx, rsp, nil)
}

// TestDelete
// @tags 测试
// @summary 测试DELETE类型请求
// @param data body msg.TestDeleteRequest true "请求参数"
// @success 200 {object} msg.TestDeleteResponse "响应参数"
// @router /test [delete]
func TestDelete(ctx *gin.Context) {
	var param msg.TestDeleteRequest
	if err := ctx.Bind(&param); err != nil {
		log.Error("TestDelete bind error:", err)
		sendMsgToHttp(ctx, nil, errors.New("参数错误, "+err.Error()))
		return
	}
	rsp := msg.TestDeleteResponse{
		ParamArrayString: param.ParamArrayString,
		ParamObject: msg.TestDeleteRequestObject{
			ParamString: param.ParamObject.ParamString,
			ParamInt:    param.ParamObject.ParamInt,
		},
	}
	sendMsgToHttp(ctx, rsp, nil)
}
